package com.example.RuanJianKeShe.Service.manager.update;

import com.alibaba.fastjson.JSON;
import com.example.RuanJianKeShe.Bean.Course;
import com.example.RuanJianKeShe.Dao.impl.CourseDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateCourseInfo")
public class updateCourseInfo extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        System.out.println(req.getParameter("msg"));
        Course course = new Course();
        course.setCname(req.getParameter("cname"));
        course.setCno(Integer.parseInt(req.getParameter("cno")));
        course.setCredit(Integer.parseInt(req.getParameter("credit")));
        course.setCapacity(req.getParameter("capacity"));
        course.setAddress(req.getParameter("address"));
        CourseDaoImpl courseDao = new CourseDaoImpl();
        Boolean flag = courseDao.setCourseById(course);
        if (flag==true){
            String jsonString = JSON.toJSONString("success");
            resp.getWriter().write(jsonString);
        }

    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }


}
